package servlet;

import cn.dsna.util.images.ValidateCode;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

/**
 * @author
 */
@WebServlet(name = "ValidateCodeServlet", value = "/validateCode")
public class ValidateCodeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //  创建验证码
        ValidateCode validateCode = new ValidateCode(100, 30, 4, 30);
        //  将验证码存储到Session
        HttpSession session = request.getSession();
        session.setAttribute("validateCode", validateCode.getCode());
        //  将验证码以图片的形式发给浏览器
        validateCode.write(response.getOutputStream());

        response.getWriter().write(validateCode.getCode());


    }


}
